// Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
// This source file is part of the Cangjie project, licensed under Apache-2.0
// with Runtime Library Exception.
//
// See https://cangjie-lang.cn/pages/LICENSE for license information.

#ifndef DEBUG_INFO_ATTACHER_H
#define DEBUG_INFO_ATTACHER_H

#include <string>
#include <vector>

#include "cangjie/Parse/Parser.h"

#include "Path.h"
#include "PositionRange.h"

namespace CangjieMigrator {

class DebugInfoAttacher {
public:
    using AttachFunc = std::function<bool(const std::string &info)>;
    using SelfDefineFunc = bool (*)(const AttachFunc &attach, const Cangjie::AST::Node &node);
    static std::vector<SelfDefineFunc> selfDefines;

    const Path file;
    const std::vector<std::string> lines;

    explicit DebugInfoAttacher(Path file);

    bool Attach(int line, const std::string &info);
    bool Attach(const Cangjie::AST::Node &node, const PositionRange &range);
    bool Generate() const;
    bool Generate(const Path &target) const;

private:
    std::vector<std::vector<std::string>> infos;
};

} // namespace CangjieMigrator

#endif // DEBUG_INFO_ATTACHER_H
